package com.zx.ishopping.mapper;


import com.zx.ishopping.VO.CartItemVo;
import com.zx.ishopping.annotation.AutoFill;
import com.zx.ishopping.entity.CartItem;
import com.zx.ishopping.enums.OperationEnum;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartItemMapper {


    /**
     * 添加新的购物车商品
     * @param cartItem
     */
    @AutoFill(value = OperationEnum.INSERT)
    @Insert("INSERT  INTO cart_items (cart_id,product_id,quantity,total_price) values (#{cartId},#{productId},#{quantity},#{totalPrice})")
    void addCartItem(CartItem cartItem);

    /**
     * 根据购物车id和商品id查询购物车商品
     * @param id
     * @param productId
     * @return
     */
    @Select("SELECT * FROM cart_items WHERE cart_id = #{id} AND product_id = #{productId}")
    int getCartItemByCartIdAndProductId(Long id, Long productId);

    /**
     * 根据购物车id查询购物车内的所有商品
     */
    
    List<CartItemVo> getCartItems(Long cartId);

    /**
     * 删除购物车商品
     * @param id
     */
    @Delete("DELETE FROM cart_items WHERE id = #{id}")
    void deleteOrderItems(Long id);
}
